{include file="include/top"}
<style>
    td,.layui-table th{
        text-align: center;!important;
    }
</style>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">管理员管理</a>
            <a>
              <cite>管理员列表</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form " action="{:url('Admin/index')}" method="get">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="g_id">
                                        <option value="">选择用户组</option>
                                        {volist name="groupList" id="groupList"}
                                        <option value="{$groupList.id}">{$groupList.title}</option>
                                        {/volist}
                                    </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="username"  placeholder="请输入用户名" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-btn" name="sub" type="submit" value="搜索">
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll('{:url(\'Admin/delList\')}')"><i class="layui-icon"></i>批量删除</button>
                            <button class="layui-btn" onclick="edit()"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table" >
                              <thead>
                                <tr>
                                  <th>
                                      <input type="checkbox" onclick="return quanxuan(this)" name="input" lay-skin="primary">
                                  </th>
                                    <th>ID</th>
                                    <th>用户名</th>
                                    <th>注册时间</th>
                                    <th>最后一次登录时间</th>
                                    <th>用户组</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                              </thead>
                              <tbody>
                              {volist name="list" id="data"}
                                <tr>
                                  <td>
                                    <input type="checkbox" name="input[]" value="{$data.ad_id}" lay-skin="primary">
                                  </td>
                                  <td>{$data.ad_id}</td>
                                  <td>{$data.ad_name}</td>
                                  <td>{if $data.ad_ztime!=''}{$data.ad_ztime|date='Y-m-d H:i:s',###}{/if}</td>
                                  <td>{if $data.ad_dtime!=''}{$data.ad_dtime|date='Y-m-d H:i:s',###}{/if}</td>
                                  <td>{$data.title}</td>
                                  <td class="td-status">
                                      {if $data.ad_state==1}<span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>
                                      {else}<span class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled">已禁用</span>{/if}
                                  </td>
                                  <td class="td-manage">
                                      {if $data.ad_state == 1}
                                      <a title="禁用" onclick="member_stop(this,'admin','ad_id','{$data.ad_id}','ad_state',0,'禁用')" href="javascript:;">
                                          <i class="iconfont">&#xe69a;</i>
                                      </a>
                                      {else}
                                      <a title="启用" onclick="member_stop(this,'admin','ad_id','{$data.ad_id}','ad_state',1,'启用')" href="javascript:;">
                                          <i class="iconfont">&#xe6ad;</i>
                                      </a>{/if}
                                    <a title="编辑"  onclick="edit('{$data.ad_id}')" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                    </a>
                                    <a title="删除" onclick="member_del('{:url(\'admin/delList\')}',this,'{$data.ad_id}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                    </a>
                                  </td>
                                </tr>
                              {/volist}
                              </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                {$page}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script>
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });

      /*用户-停用*/
      function member_stop(obj,table,id,where,field,state,title){
          layer.confirm('确认要'+title +'吗？',function(index){
              $.ajax({
                  type: 'POST',
                  url: '{:url("index/updateStatus")}',
                  dataType: 'json',
                  data : {table:table,id:id,where:where,field:field,state:state},
                  success: function(data){
                      if(data.code>0){
                          layer.msg('已'+obj.title,{icon:1,time:1000});
                          setTimeout(function () {
                              location.reload();
                          }, 1000);
                      }else{
                          layer.msg(obj.title+'失败',{icon:1,time:1000});
                      }

                  },
                  error:function(data) {
                      console.log(data.msg);
                  },
              });
          });
      }
      //全选
      function quanxuan(i) {
          console.log(i);
          var checkboxs = $("[name='input[]']");
          for(var n=0;n<checkboxs.length;n++){
              checkboxs[n].checked = i.checked ;
          }
      }
      function edit(id = '')
      {
          if(id==''){
              var url = '{:url("Admin/add")}';
          }else{
              var url = '{:url("Admin/edit",["id"=>"getId"])}';
              url = url.replace('getId',id);
          }
          var loading =  layer.load(0, {shade: false});
          layer.open({
              type: 2,
              title:'编辑',
              area: ['50%', '80%'],
              content: url
          });
          layer.close(loading);
      }

      /*删除*/
      function member_del(url,obj,id){
          layer.confirm('确认要删除吗？',function(index){
              $.ajax({
                  type: 'POST',
                  url: url,
                  dataType: 'json',
                  data : {id:id},
                  success: function(data){
                      $(obj).parents("tr").remove();
                      layer.msg('已删除!',{icon:1,time:1000});
                  },
                  error:function(data) {
                      console.log(data.msg);
                  },
              });
          });
      }
      /*批量删除*/
      function delAll(url) {
          var obj = document.getElementsByName("input[]");
          var check_val = [];
          for (var k in obj) {
              if (obj[k].checked)
                  check_val.push(obj[k].value);
          }
          if (check_val == '') {
              layer.msg('请选择要删除的内容!');
          } else {
              layer.confirm('确认要删除吗？', function (index) {
                  $.ajax({
                      type: 'POST',
                      url: url,
                      data: {id: check_val},
                      success: function (data) {
                          layer.msg('已删除!', {icon: 1, time: 1000});
                          setTimeout(function () {
                              location.reload();
                          }, 1000);
                      },
                      error: function (data) {
                          console.log(data.msg);
                      },
                  });
              });
          }

      }
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
</html>